package com.zzhua.controller;

import com.zzhua.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Collection;

@RestController
@RequestMapping("/myRest")
public class MyRestController {

    @Autowired
    private RestTemplate restTemplate;

    // 将所有的ip:port 改成 注册的服务的名字
    // restTemplate被增强了，所以能识别到了provider
    @GetMapping("findAll")
    public Collection<Student> findAll(){
        return restTemplate.getForEntity("http://provider/student/findAll", Collection.class).getBody();
    }

    // 根据port端口，测试调用的是哪个服务
    @GetMapping("port")
    public String port(){
        return restTemplate.getForEntity("http://provider/student/port", String.class).getBody();
    }
}
